<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>查询结果</title>
<link rel="stylesheet" href="layui/css/layui.css" media="all">
</head>
<body>
	<div style="width: 700px; margin: 0 auto;">
		<div class="layui-row">
			<div class="layui-col-xs6">
				<div class="grid-demo grid-demo-bg1">
					<p>&nbsp;</p>
				</div>
			</div>
			<div class="layui-col-xs6">
				<div class="grid-demo">
					<span style="margin-right: 30px">当前用户：${sessionScope.user.name }</span>
					<a class="layui-btn layui-btn-primary layui-btn-xs"
						href="user.do?action=showUpdate">修改密码</a> <a
						class="layui-btn layui-btn-primary layui-btn-xs"
						href="user.do?action=logout">退出登录</a>
				</div>
			</div>
		</div>
		<fieldset class="layui-elem-field layui-field-title"
			style="margin-top: 20px;">
			<legend>查询结果</legend>
		</fieldset>
		<div class="layui-form">
			<form id="myForm" class="layui-form" action="book.do?action=delete"
				method="post">
				<c:if test="${empty list }">
					<div style="text-align: center; margin: auto; line-height: 100px;">
						<h1>抱歉，当前没有可以显示的数据！</h1>
					</div>
				</c:if>
				<c:if test="${!empty list }">
					<table class="layui-table">
						<colgroup>
							<col width="60">
							<col width="60">
							<col width="150">
							<col width="95">
							<col width="150">
							<col width="80">
							<col width="105">
						</colgroup>
						<thead>
							<tr>
								<th style="text-align: center">选择</th>
								<th style="text-align: center">序号</th>
								<th style="text-align: center">书名</th>
								<th style="text-align: center">作者</th>
								<th style="text-align: center">出版社</th>
								<th style="text-align: center">价格</th>
								<th style="text-align: center">操作</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${list }" var="item" varStatus="status">
								<tr>
									<td><input type="checkbox" name="ids" value="${item.id }"
										lay-skin="primary"></td>
									<td>${status.count }</td>
									<td>${item.bookName }</td>
									<td>${item.author }</td>
									<td>${item.pub }</td>
									<td>${item.price }</td>
									<td><div id="editBtn">
											<a data-method="confirm" data-id="${item.id }"
												class="layui-btn layui-btn-primary layui-btn-xs"><i
												class="layui-icon"></i></a> <a
												class="layui-btn layui-btn-primary layui-btn-xs"
												href="book.do?action=querybyid&id=${item.id }"><i
												class="layui-icon"></i></a>
										</div></td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					<div class="layui-form-item">
						<input type="button" id="allBook" value="全选"
							class="layui-btn layui-btn-primary layui-btn-sm"><input
							type="button" id="backBook" value="反选"
							class="layui-btn layui-btn-primary layui-btn-sm"><a
							id="delete" class="layui-btn layui-btn-primary layui-btn-sm"
							name="delete">删除选中</a>
					</div>
				</c:if>
			</form>
		</div>
	</div>
	<div class="layui-form-item"
		style="text-align: center; margin: 0 auto;">
		<a class="layui-btn layui-btn-primary" href="book.do?type=gotoadd">添加</a>
		<a class="layui-btn layui-btn-primary layui-btn-radius"
			href="book.do?type=gotoindex">回主页</a>
	</div>
	<script src="layui/layui.js" charset="utf-8"></script>
	<script type="text/javascript">
		layui.use([ 'form', 'layedit', 'laydate', 'layer' ], function() {
			var form = layui.form, $ = layui.jquery, layer = layui.layer;
			var active = {
				confirm : function(othis) {
					layer.confirm('真的要删除这本书吗?', {
						icon : 3,
						title : '警告'
					}, function(index) {
						var id = othis.data('id');
						window.location.href = "book.do?action=deletebyid&id="
								+ id;
						layer.close(index);
					});
				}
			};
			$('#editBtn .layui-btn').on('click', function() {
				var othis = $(this), method = othis.data('method');
				active[method] ? active[method].call(this, othis) : '';
			});
			$("#delete").click(function() {
				layer.confirm('真的要删除这些书吗?', {
					icon : 3,
					title : '警告'
				}, function(index) {
					$('#myForm').submit();
					layer.close(index);
				});
			});
			$('#allBook').click(function() {
				$("input[type=checkbox]").each(function() {
					this.checked = true;
				})
				form.render('checkbox');
			});
			$('#backBook').click(function() {
				$("input[type=checkbox]").each(function() {
					this.checked = !this.checked;
				})
				form.render('checkbox');
			});
		});
	</script>
</body>
</html>